<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "department".
 *
 * @property int $ID ID
 * @property int $XXID 学校ID
 * @property string $BMMC 部门名称
 * @property string $BMDM 部门代码
 * @property string $FZRXM 负责人姓名
 * @property string|null $FZRGH 负责人工号
 * @property string|null $JJ 简介
 * @property string $CLSJ 成立时间
 * @property string|null $CXSJ 撤销时间
 * @property string $ZT 状态
 *
 * @property School $xX
 * @property Major[] $majors
 * @property Teacher[] $teachers
 */
class Department extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'department';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['XXID', 'BMMC', 'BMDM', 'FZRXM', 'CLSJ', 'ZT'], 'required'],
            [['XXID'], 'integer'],
            [['JJ'], 'string'],
            [['CLSJ', 'CXSJ'], 'safe'],
            [['BMMC', 'FZRXM'], 'string', 'max' => 50],
            [['BMDM', 'FZRGH'], 'string', 'max' => 20],
            [['ZT'], 'string', 'max' => 10],
            [['XXID'], 'exist', 'skipOnError' => true, 'targetClass' => School::className(), 'targetAttribute' => ['XXID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'XXID' => '学校ID',
            'BMMC' => '部门名称',
            'BMDM' => '部门代码',
            'FZRXM' => '负责人姓名',
            'FZRGH' => '负责人工号',
            'JJ' => '简介',
            'CLSJ' => '成立时间',
            'CXSJ' => '撤销时间',
            'ZT' => '状态',
        ];
    }

    /**
     * Gets query for [[XX]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getXX()
    {
        return $this->hasOne(School::className(), ['ID' => 'XXID'])->inverseOf('departments');
    }

    /**
     * Gets query for [[Majors]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getMajors()
    {
        return $this->hasMany(Major::className(), ['BMID' => 'ID'])->inverseOf('bM');
    }

    /**
     * Gets query for [[Teachers]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getTeachers()
    {
        return $this->hasMany(Teacher::className(), ['BMID' => 'ID'])->inverseOf('bM');
    }
}
